﻿#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio.hpp>
#include <boost/asio/thread_pool.hpp>
#include <map>
#include <functional>
#include <tuple>
#include <string>
#include <iostream>
#include <memory>
#include <future>
#include <thread>
#include <chrono>
// 定义 HTTP 方法枚举
enum class HttpMethod {
    GET,
    POST,
    PUT,
    PATCH
};

// 定义内容类型枚举
enum class ContentType {
    JSON,
    FORM,
    TEXT,
    HTML,
    ANY // 匹配任何内容类型
};

// 请求上下文结构体
struct RequestContext {
    std::string path;
    HttpMethod method;
    ContentType contentType;
    std::string body;
    std::map<std::string, std::string> headers;
    std::map<std::string, std::string> queryParams;

    // 获取查询参数
    std::string getQueryParam(const std::string &key, const std::string &defaultValue = "") const {
        auto it = queryParams.find(key);
        return it != queryParams.end() ? it->second : defaultValue;
    }
};

// 响应结构体
struct HttpResponse {
    int statusCode = 200;
    std::string body;
    std::map<std::string, std::string> headers;

    HttpResponse(int code = 200, const std::string &content = "")
        : statusCode(code), body(content) {
    }
};

// 路由键类型
using RouteKey = std::tuple<std::string, HttpMethod, ContentType>;

// 自定义比较函数
struct RouteKeyCompare {
    bool operator()(const RouteKey &a, const RouteKey &b) const {
        return a < b;
    }
};

// 路由处理器函数类型
// using RouteHandler = HttpResponse(*)(const RequestContext&);
using RouteHandler = std::function<HttpResponse(const RequestContext &)>;

